package com.iot08.api.exception;

import com.iot08.common.utils.response.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @version 1.0
 * @Description:
 * @time: 2020/12/23 10:29
 * @author: Rock
 */
//使用 @ControllerAdvice 实现全局异常处理
@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = ServerException.class)
    public ResponseMap exceptionHandler(ServerException exception) {
        ResponseMap res = ResponseMap.fail(exception.getCode(), exception.getMessage());
        return res;
    }

}
